package com.yb.guigu.pick.code.generator.service;

import com.yb.guigu.pick.core.constant.MobileType;
import com.yb.guigu.pick.core.domain.mq.MobileCodeSend;
import com.yb.guigu.pick.core.domain.mq.MobileMessageSend;
import com.yb.guigu.pick.core.util.StringUtil;
import com.yb.guigu.pick.mobile.sender.bean.MobileSenderRequest;
import com.yb.guigu.pick.mobile.sender.bean.MobileSenderResponse;
import com.yb.guigu.pick.mobile.sender.sender.IMobileSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.UUID;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/12 17:05
 * FileName: MobileServiceImpl
 * Description:
 */

@Service
@Slf4j
public class MobileServiceImpl implements IMobileService{

    @Autowired
    IMobileSender mobileSender;

    @Override
    @Async
    public void sendMobileCode(MobileCodeSend mobileCodeSend) {
        String uuid = mobileCodeSend.getUuid();

        if(!StringUtils.hasText(uuid)){
            uuid=UUID.randomUUID().toString().replace("-","");
        }
        MobileSenderRequest senderRequest = MobileSenderRequest.builder().sendTo(mobileCodeSend.getMobile())
                .type(MobileType.MOBILE_CODE.getName())
                .template(MobileType.MOBILE_CODE.getName())
                .args(new Object[]{mobileCodeSend.getCode()})
                .uuid(uuid)
                .build();

        log.info("senderRequest:{}",senderRequest);

        MobileSenderResponse senderResponse = mobileSender.send(senderRequest);

        log.info("senderResponse:{}",senderResponse);
    }

    @Override
    public void handle(MobileMessageSend mobileMessageSend) {
        if(!StringUtils.hasText(mobileMessageSend.getType())){
            log.error("mobileMessageType is null");
            return;
        }
        String type = mobileMessageSend.getType();

    }
}
